*** Creates estimates for Table A1 and Figures 2 from the 2000-04 panel data

*** Creation of 56/60, 72/76, 92/96, and 00/04 data files documented in dataverse for 2017 AJPS - Polarization and the Decline of the American Floating Voter - dataverse link: https://doi.org/10.7910/DVN/4FCVUR


use "data/amelia00s.dta" 
merge 1:1 id using data/observed00s.dta, keepusing(pref00 pref04) 
drop _merge

merge 1:1 id using "data/id_panel2000.dta"
drop _merge


tab pid00 [iw=WT00PRE]
tab pid04 [iw=WT04]



gen partyidswitch = 0 if pid00!=. & pid04!=.
replace partyidswitch = 1 if pid00<=2 & pid04>=4 & pid04<7
replace partyidswitch = 1 if pid00>=4 & pid00<7 & pid04<=2
proportion partyidswitch [pw=WT04]

tab pref00
recode pref00 4=.

gen prefswitch = 0 if pref00!=. & pref04!=.
replace prefswitch = 1 if pref00==1 & pref04==2
replace prefswitch = 1 if pref00==2 & pref04==1
proportion prefswitch [pw=WT04]

drop partyidswitch prefswitch

gen demvreppref00 = 1 if pref00==1
replace demvreppref00 = 0 if pref00==2
tab demvreppref00 pref00

gen demvreppref04 = 1 if pref04==1
replace demvreppref04 = 0 if pref04==2

gen prefswitch = 0 if demvreppref00!=. & demvreppref04!=.
replace prefswitch = 1 if demvreppref00!=demvreppref04 & prefswitch!=.

proportion prefswitch [pw=WT04]

drop prefswitch  

desc

recode presapprove00 4=3 5=4
recode presapprove02 4=3 5=4
recode presapprove04 4=3 5=4

mi set mlong

misstable summarize

mi register imputed age black catholic education attend00 conversion00 polsoph00 cooperate00 pid00 demcandtherm_pre00 repcandtherm_pre00 demtherm00 reptherm00 presapprove00 prepref00 pid02 econ02 presapprove02 pid04 presapprove04 betterworse04 demcandtherm04 repcandtherm04 pref00 pref04

*** Full: south midwest female west

mi impute chained (truncreg, ll(18) ul(97) omit(i.prepref00 demtherm00 reptherm00 demcandtherm_pre00 repcandtherm_pre00 presapprove00 i.pid02 econ02 presapprove02 repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04 i.pref00 i.pref04)) age (logit, omit(i.prepref00  demtherm00 reptherm00 demcandtherm_pre00 repcandtherm_pre00 presapprove00 i.pid02 econ02 presapprove02 repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04  i.pref00 i.pref04)) catholic black (ologit, ascontinuous omit(i.prepref00  demtherm00 reptherm00 demcandtherm_pre00 repcandtherm_pre00 i.pid02 econ02 presapprove02 repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04  i.pref00 i.pref04 )) education attend00 conversion00 polsoph00 cooperate00 presapprove00 (ologit, omit(i.prepref00 i.pid02 econ02 presapprove02 repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04  i.pref00 i.pref04)) pid00(truncreg, ll(0) ul(100) omit(i.prepref00 i.pid02 econ02 presapprove02 repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04 i.pref00 i.pref04)) demcandtherm_pre00 repcandtherm_pre00  demtherm00 reptherm00 (mlogit, augment omit(i.pid02 econ02 presapprove02 repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04  i.pref00 i.pref04)) prepref00  (mlogit, augment omit(i.pid02 econ02 presapprove02 repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04 i.pref04)) pref00   (ologit, omit(repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04 i.prepref00 i.pref04)) pid02 (ologit, ascontinuous omit(repcandtherm04 i.pid04 betterworse04 presapprove04 demcandtherm04  i.prepref00 i.pref04)) econ02 presapprove02 (ologit, omit(i.prepref00 demcandtherm_pre00 repcandtherm_pre00 presapprove00 i.pref04)) pid04 (ologit, ascontinuous omit(i.prepref00 i.pref00 i.pref04)) presapprove04 betterworse04 (truncreg, ll(0) ul(100) omit(i.prepref00 i.pref04)) demcandtherm04 repcandtherm04  (mlogit, augment omit(i.pid00 i.pid02 presapprove00 i.prepref00 demcandtherm_pre00 repcandtherm_pre00 econ02 presapprove02 reptherm00 demtherm00)) pref04  = female south midwest west, add(40) burnin(20) chaindots rseed(334455)

mi estimate: proportion pid00 [pw=WT00PRE]
mi estimate: proportion pid04 [pw=WT00PRE]

mi passive: gen partyidswitch = 0 if pid00!=. & pid04!=.
mi passive: replace partyidswitch = 1 if pid00<=2 & pid04>=4 & pid04<7
mi passive: replace partyidswitch = 1 if pid00>=4 & pid00<7 & pid04<=2

mi estimate: proportion partyidswitch [pw=WT00PRE]

mi estimate, saving(mi_mlogit00, replace): mlogit pref00 i.pid00  demcandtherm_pre00 repcandtherm_pre00 demtherm00 reptherm00 presapprove00 i.prepref00 age female black catholic attend00, base(1)
mi predict xb00_1_mi using mi_mlogit00
mi predict xb00_2_mi using mi_mlogit00, equation(#2)
mi predict xb00_3_mi using mi_mlogit00, equation(#3)
mi xeq 0: summarize xb00_1_mi xb00_2_mi xb00_3_mi

mi passive: gen demvrepphat00 = 1/(1+exp(xb00_2_mi))
mi estimate: mean demvrepphat00
mi passive: gen simdem00 = uniform()<=demvrepphat00
mi passive: gen demvrepchoice00 = demvreppref00
mi passive: replace demvrepchoice00 = simdem00 if demvrepchoice00==.

mi estimate, saving(mi_mlogit04, replace): mlogit pref04 i.pid04 demcandtherm04 repcandtherm04 presapprove04 i.pref00 betterworse04 age female black catholic attend00, base(1) 

mi predict xb04_1_mi using mi_mlogit04
mi predict xb04_2_mi using mi_mlogit04, equation(#2)
mi predict xb04_3_mi using mi_mlogit04, equation(#3)
mi xeq 0: summarize xb04_1_mi xb04_2_mi xb04_3_mi

mi passive: gen demvrepphat04 = 1/(1+exp(xb04_2_mi))
mi estimate: mean demvrepphat04
mi passive: gen simdem04 = uniform()<=demvrepphat04
mi passive: gen demvrepchoice04 = demvreppref04
mi passive: replace demvrepchoice04 = simdem04 if demvrepchoice04==.

mi estimate: proportion demvrepchoice00 demvrepchoice04 [pw=WT00PRE]

mi passive: gen supportswitch = 0 if pref00!=. & pref04!=.
mi passive: replace supportswitch = 1 if pref00==1 & pref04==2
mi passive: replace supportswitch = 1 if pref00==2 & pref04==1

mi estimate: proportion supportswitch [pw=WT00PRE]

drop supportswitch


***************
** no 3rd party
***************

** make sure imputed values are consistent

mi passive: gen supportswitch = 0 if demvrepchoice00!=. & demvrepchoice04!=.
mi passive: replace supportswitch = 1 if demvrepchoice00!=demvrepchoice04
mi estimate: proportion supportswitch [pw=WT00PRE]

